/**
 * @description 音乐操作
 */

import { objecter, loger } from '@daelui/dogjs/dist/components.js'
import ds, { database } from './service.js'
import request from '@/utils/request'
import config from '@/common/config.js'

export default {
  // 查询所有
  queryListAll (query, options) {
    return request({
      url: config.playlistUrl + '/dpod/assets/js/playlist.json',
      method: 'get',
      params: query
    }).then(res => {
      res = Array.isArray(res) ? res : []
      res.forEach(item => {
        item.url = config.playlistUrl + '/dpod/' + item.url
        if (item.cover) {
          item.cover = config.playlistUrl + '/dpod/' + item.cover
        }
        if (item.lrc) {
          item.lrc = config.playlistUrl + '/dpod/' + item.lrc
        }
      })
      return res
    })
  },
  // 查询列表(分页)
  queryListByPage (data, options) {
    options = options || {}
    options.sort = options.sort || [{ field: 'createTime', by: 'desc' }]
    return database.table('dpod_music').queryByPage(data, options)
  },
  // 查询列表
  queryList (data, options) {
    options = options || {}
    options.sort = options.sort || [{ field: 'createTime', by: 'desc' }]
    return database.table('dpod_music').select(data, options)
  },
  // 查询单个
  queryItem (data, options) {
    return database.table('dpod_music').select(data, options).then(list => {
			list = Array.isArray(list) ? list : []
			return list[0]
		})
  },
  // 添加
  insert (data) {
    return database.table('dpod_music').insert(data)
  },
  // 更新
  update (data, options) {
    return database.table('dpod_music').update(data, options)
  },
  // 删除
  delete (data, options) {
    return database.table('dpod_music').delete(data, options)
  }
}

export {
  database
}
